#include "stdafx.h"
#include "TNavigate.h"
#include "TNavigateDoc.h"
#include "TNavigateView.h"
#include "topengl.h"
#include "PropertiesWnd.h"
#include "UIPattern.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNCREATE(CTNavigateView, CView)

BEGIN_MESSAGE_MAP(CTNavigateView, CView)
	ON_WM_SIZE()
	ON_WM_DESTROY()
	ON_WM_CREATE()
	ON_WM_ERASEBKGND()
	ON_WM_SETCURSOR()
END_MESSAGE_MAP()

CTNavigateView::CTNavigateView() : m_pGL(NULL), m_PattMgr(NULL), m_pDB(NULL)
{
	m_PattMgr = new UIPatternManager(this);
}

CTNavigateView::~CTNavigateView()
{
	m_pDB = NULL;
	if (m_pGL)
	{
		delete m_pGL;
		m_pGL = NULL;
	}
	if (m_PattMgr)
	{
		delete m_PattMgr;
		m_PattMgr = NULL;
	}
}

void CTNavigateView::OnContextMenu(CWnd* pWnd, CPoint point) { theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE); }

void CTNavigateView::OnDraw(CDC *pDC)
{
	m_pGL->Draw();
}
void CTNavigateView::OnSize(UINT nType, int cx, int cy)
{
	m_pGL->ChangeSize(cx, cy);
	CView::OnSize(nType, cx, cy);
}

void CTNavigateView::OnDestroy()
{
	CView::OnDestroy();
}

int CTNavigateView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	m_pGL = new TOpenGL(this);
	m_pGL->Initialize();
	return 0;
}

BOOL CTNavigateView::OnEraseBkgnd(CDC* pDC) { return TRUE; }

BOOL CTNavigateView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { return TRUE; }

LRESULT CTNavigateView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	if (!m_PattMgr->RoutingWM(message, wParam, lParam))
		return CView::WindowProc(message, wParam, lParam);
	else
		return NULL;
}